/*
 * Created by JFormDesigner on Thu Apr 14 18:07:16 CST 2022
 */

package com.ZengQi.event.view;

import com.ZengQi.event.controller.LookCommentViewController;
import com.ZengQi.event.entity.Comment;

import java.awt.*;
import java.awt.event.*;
import java.util.List;
import java.util.Vector;
import javax.swing.*;
import javax.swing.GroupLayout;
import javax.swing.table.*;

/**
 * @author QI Zeng
 */
public class LookCommentView extends JFrame {
    private String topicName;
    private List<Comment> list=null;
    private LookCommentViewController lookCommentViewController=new LookCommentViewController();

    public LookCommentView(String topicName) {
        initComponents();
        this.topicName=topicName;
        Comment conditionComment=new Comment();
        conditionComment.setTopicName(topicName);
        list=lookCommentViewController.commentList(conditionComment);
        if(list!=null){
            int i=0;
            DefaultTableModel dtm=(DefaultTableModel) table1.getModel();
            dtm.setRowCount(0);
            for(Comment comment:list){
                Vector<String>vector=new Vector<String>();
                vector.add(comment.getCommentContent());
                vector.add(comment.getCommentPublisher());
                dtm.addRow(vector);
            }

        }

        setVisible(true);
        setLocationRelativeTo(null);


    }

    private void commentTableMousePressed(MouseEvent e) {
        commentTablepressed(e);
    }

    private void commentTablepressed(MouseEvent e) {
        int row=table1.getSelectedRow();
        Comment comment= list.get(row);
        commentTxt.setText(comment.getCommentContent());


    }

    private void backBtn(ActionEvent e) {
        backBtnActionPerformed(e);
    }

    private void backBtnActionPerformed(ActionEvent e) {
        dispose();
    }


    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        scrollPane1 = new JScrollPane();
        table1 = new JTable();
        panel1 = new JPanel();
        label1 = new JLabel();
        scrollPane2 = new JScrollPane();
        commentTxt = new JTextArea();
        button1 = new JButton();

        //======== this ========
        setIconImage(new ImageIcon(getClass().getResource("/bang.png")).getImage());
        setTitle("\u505a\u9898\u5e2e");
        Container contentPane = getContentPane();

        //======== scrollPane1 ========
        {

            //---- table1 ----
            table1.setModel(new DefaultTableModel(
                new Object[][] {
                    {null, null},
                    {null, null},
                },
                new String[] {
                    "\u8bc4\u8bba", "\u8bc4\u8bba\u8005"
                }
            ) {
                boolean[] columnEditable = new boolean[] {
                    false, false
                };
                @Override
                public boolean isCellEditable(int rowIndex, int columnIndex) {
                    return columnEditable[columnIndex];
                }
            });
            {
                TableColumnModel cm = table1.getColumnModel();
                cm.getColumn(0).setResizable(false);
                cm.getColumn(0).setPreferredWidth(220);
                cm.getColumn(1).setResizable(false);
                cm.getColumn(1).setPreferredWidth(220);
            }
            table1.addMouseListener(new MouseAdapter() {
                @Override
                public void mousePressed(MouseEvent e) {
                    commentTableMousePressed(e);
                }
            });
            scrollPane1.setViewportView(table1);
        }

        //======== panel1 ========
        {

            //---- label1 ----
            label1.setText("\u8bc4\u8bba");

            //======== scrollPane2 ========
            {

                //---- commentTxt ----
                commentTxt.setEditable(false);
                scrollPane2.setViewportView(commentTxt);
            }

            GroupLayout panel1Layout = new GroupLayout(panel1);
            panel1.setLayout(panel1Layout);
            panel1Layout.setHorizontalGroup(
                panel1Layout.createParallelGroup()
                    .addGroup(panel1Layout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addComponent(label1, GroupLayout.PREFERRED_SIZE, 53, GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(scrollPane2, GroupLayout.PREFERRED_SIZE, 532, GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(149, Short.MAX_VALUE))
            );
            panel1Layout.setVerticalGroup(
                panel1Layout.createParallelGroup()
                    .addGroup(panel1Layout.createSequentialGroup()
                        .addGap(14, 14, 14)
                        .addComponent(label1)
                        .addContainerGap(85, Short.MAX_VALUE))
                    .addGroup(GroupLayout.Alignment.TRAILING, panel1Layout.createSequentialGroup()
                        .addGap(0, 6, Short.MAX_VALUE)
                        .addComponent(scrollPane2, GroupLayout.PREFERRED_SIZE, 115, GroupLayout.PREFERRED_SIZE))
            );
        }

        //---- button1 ----
        button1.setText("\u8fd4\u56de");
        button1.addActionListener(e -> backBtn(e));

        GroupLayout contentPaneLayout = new GroupLayout(contentPane);
        contentPane.setLayout(contentPaneLayout);
        contentPaneLayout.setHorizontalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addGroup(contentPaneLayout.createParallelGroup()
                        .addGroup(contentPaneLayout.createSequentialGroup()
                            .addGap(19, 19, 19)
                            .addComponent(panel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(contentPaneLayout.createSequentialGroup()
                            .addGroup(contentPaneLayout.createParallelGroup()
                                .addGroup(contentPaneLayout.createSequentialGroup()
                                    .addGap(46, 46, 46)
                                    .addComponent(scrollPane1, GroupLayout.PREFERRED_SIZE, 680, GroupLayout.PREFERRED_SIZE))
                                .addGroup(contentPaneLayout.createSequentialGroup()
                                    .addGap(367, 367, 367)
                                    .addComponent(button1)))
                            .addGap(0, 71, Short.MAX_VALUE)))
                    .addContainerGap())
        );
        contentPaneLayout.setVerticalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(scrollPane1, GroupLayout.PREFERRED_SIZE, 177, GroupLayout.PREFERRED_SIZE)
                    .addGap(58, 58, 58)
                    .addComponent(panel1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
                    .addComponent(button1)
                    .addGap(26, 26, 26))
        );
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JScrollPane scrollPane1;
    private JTable table1;
    private JPanel panel1;
    private JLabel label1;
    private JScrollPane scrollPane2;
    private JTextArea commentTxt;
    private JButton button1;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
